home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / man / cat3 / CrtErrHdlr.3 < prev    next >
Text File  |  1994-09-20  |  9KB  |  265 lines

  1.  
  2.  
  3.  
  4. Tk_CreateErrorHandler(3T)k Library Procedures
  5.  
  6.  
  7.  
  8. _________________________________________________________________
  9.  
  10. NAME
  11.      Tk_CreateErrorHandler, Tk_DeleteErrorHandler - handle X pro-
  12.      tocol errors
  13.  
  14. SYNOPSIS
  15.      #include <tk.h>
  16.  
  17.      Tk_ErrorHandler
  18.      Tk_CreateErrorHandler(_d_i_s_p_l_a_y, _e_r_r_o_r, _r_e_q_u_e_s_t, _m_i_n_o_r, _p_r_o_c, _c_l_i_e_n_t_D_a_t_a)
  19.  
  20.      Tk_DeleteErrorHandler(_h_a_n_d_l_e_r)
  21.  
  22. ARGUMENTS
  23.      Display           *_d_i_s_p_l_a_y     (in)      Display       whose
  24.                                               errors  are  to  be
  25.                                               handled.
  26.  
  27.      int               _e_r_r_o_r        (in)      Match  only   error
  28.                                               events   with  this
  29.                                               value    in     the
  30.                                               _e_r_r_o_r__c_o_d_e   field.
  31.                                               If -1,  then  match
  32.                                               any      _e_r_r_o_r__c_o_d_e
  33.                                               value.
  34.  
  35.      int               _r_e_q_u_e_s_t      (in)      Match  only   error
  36.                                               events   with  this
  37.                                               value    in     the
  38.                                               _r_e_q_u_e_s_t__c_o_d_e field.
  39.                                               If -1,  then  match
  40.                                               any    _r_e_q_u_e_s_t__c_o_d_e
  41.                                               value.
  42.  
  43.      int               _m_i_n_o_r        (in)      Match  only   error
  44.                                               events   with  this
  45.                                               value    in     the
  46.                                               _m_i_n_o_r__c_o_d_e   field.
  47.                                               If -1,  then  match
  48.                                               any      _m_i_n_o_r__c_o_d_e
  49.                                               value.
  50.  
  51.      Tk_ErrorProc      *_p_r_o_c        (in)      Procedure to invoke
  52.                                               whenever  an  error
  53.                                               event  is  received
  54.                                               for   _d_i_s_p_l_a_y   and
  55.                                               matches      _e_r_r_o_r,
  56.                                               _r_e_q_u_e_s_t, and _m_i_n_o_r.
  57.                                               NULL  means  ignore
  58.                                               any        matching
  59.                                               errors.
  60.  
  61.  
  62.  
  63. Tk                                                              1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Tk_CreateErrorHandler(3T)k Library Procedures
  71.  
  72.  
  73.  
  74.      ClientData        _c_l_i_e_n_t_D_a_t_a   (in)      Arbitrary  one-word
  75.                                               value  to  pass  to
  76.                                               _p_r_o_c.
  77.  
  78.      Tk_ErrorHandler   _h_a_n_d_l_e_r      (in)      Token   for   error
  79.                                               handler  to  delete
  80.                                               (return value  from
  81.                                               a  previous call to
  82.                                               Tk_CreateErrorHandler).
  83. _________________________________________________________________
  84.  
  85.  
  86. DESCRIPTION
  87.      Tk_CreateErrorHandler arranges for  a  particular  procedure
  88.      (_p_r_o_c)  to  be called whenever certain protocol errors occur
  89.      on a particular display (_d_i_s_p_l_a_y).   Protocol  errors  occur
  90.      when  the X protocol is used incorrectly, such as attempting
  91.      to map a window that doesn't exist.  See the Xlib documenta-
  92.      tion  for XSetErrorHandler for more information on the kinds
  93.      of errors that can occur.  For _p_r_o_c to be invoked to  handle
  94.      a particular error, five things must occur:
  95.  
  96.      [1]  The error must pertain to _d_i_s_p_l_a_y.
  97.  
  98.      [2]  Either the _e_r_r_o_r argument to Tk_CreateErrorHandler must
  99.           have  been  -1,  or  the  _e_r_r_o_r argument must match the
  100.           _e_r_r_o_r__c_o_d_e field from the error event.
  101.  
  102.      [3]  Either the _r_e_q_u_e_s_t  argument  to  Tk_CreateErrorHandler
  103.           must  have  been -1, or the _r_e_q_u_e_s_t argument must match
  104.           the _r_e_q_u_e_s_t__c_o_d_e field from the error event.
  105.  
  106.      [4]  Either the _m_i_n_o_r argument to Tk_CreateErrorHandler must
  107.           have  been  -1,  or  the  _m_i_n_o_r argument must match the
  108.           _m_i_n_o_r__c_o_d_e field from the error event.
  109.  
  110.      [5]  The protocol request to which the error  pertains  must
  111.           have  been  made when the handler was active (see below
  112.           for more information).
  113.  
  114.      _P_r_o_c should have arguments and result that match the follow-
  115.      ing type:
  116.           typedef int Tk_ErrorProc(
  117.                ClientData _c_l_i_e_n_t_D_a_t_a,
  118.                XErrorEvent *_e_r_r_E_v_e_n_t_P_t_r);
  119.      The _c_l_i_e_n_t_D_a_t_a parameter to _p_r_o_c is a copy of the _c_l_i_e_n_t_D_a_t_a
  120.      argument  given  to Tcl_CreateErrorHandler when the callback
  121.      was created.  Typically, _c_l_i_e_n_t_D_a_t_a points to a data  struc-
  122.      ture  containing  application-specific  information  that is
  123.      needed to deal with the error.  _E_r_r_E_v_e_n_t_P_t_r is a pointer  to
  124.      the  X  error  event.   The  procedure _p_r_o_c should return an
  125.      integer value.  If it returns 0 it means that  _p_r_o_c  handled
  126.  
  127.  
  128.  
  129. Tk                                                              2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. Tk_CreateErrorHandler(3T)k Library Procedures
  137.  
  138.  
  139.  
  140.      the  error completely and there is no need to take any other
  141.      action for the error.  If it returns non-zero it means  _p_r_o_c
  142.      was unable to handle the error.
  143.  
  144.      If a value of NULL  is  specified  for  _p_r_o_c,  all  matching
  145.      errors  will  be ignored:  this will produce the same result
  146.      as if a procedure had been specified that always returns 0.
  147.  
  148.      If more than more than  one  handler  matches  a  particular
  149.      error,  then they are invoked in turn.  The handlers will be
  150.      invoked  in  reverse  order  of  creation:   most   recently
  151.      declared handler first.  If any handler returns 0, then sub-
  152.      sequent (older) handlers will not be invoked.  If no handler
  153.      returns 0, then Tk invokes X'es default error handler, which
  154.      prints an error message and aborts the program.  If you wish
  155.      to  have  a  default  handler that deals with errors that no
  156.      other handler can deal with, then declare it first.
  157.  
  158.      The X documentation states that ``the error  handler  should
  159.      not  call  any  functions  (directly  or  indirectly) on the
  160.      display that will generate protocol requests  or  that  will
  161.      look   for  input  events.''  This  restriction  applies  to
  162.      handlers declared by Tk_CreateErrorHandler;  disobey  it  at
  163.      your own risk.
  164.  
  165.      Tk_DeleteErrorHandler may be called to delete a  previously-
  166.      created  error handler.  The _h_a_n_d_l_e_r argument identifies the
  167.      error handler, and should be a value returned by a  previous
  168.      call to Tk_CreateEventHandler.
  169.  
  170.      A particular error handler applies to errors resulting  from
  171.      protocol    requests   generated   between   the   call   to
  172.      Tk_CreateErrorHandler and the call to Tk_DeleteErrorHandler.
  173.      However,  the  actual  callback  to _p_r_o_c may not occur until
  174.      after the Tk_DeleteErrorHandler call, due  to  buffering  in
  175.      the client and server.  If an error event pertains to a pro-
  176.      tocol     request     made     just      before      calling
  177.      Tk_DeleteErrorHandler,  then  the  error  event may not have
  178.      been processed before the Tk_DeleteErrorHandler call.   When
  179.      this  situation  arises,  Tk will save information about the
  180.      handler and invoke the handler's _p_r_o_c later when  the  error
  181.      event  finally  arrives.  If an application wishes to delete
  182.      an error handler and know  for  certain  that  all  relevant
  183.      errors   have   been   processed,   it   should  first  call
  184.      Tk_DeleteErrorHandler and then call XSync;  this will  flush
  185.      out  any  buffered requests and errors, but will result in a
  186.      performance penalty because it requires communication to and
  187.      from  the  X  server.  After the XSync call Tk is guaranteed
  188.      not to call any error  handlers  deleted  before  the  XSync
  189.      call.
  190.  
  191.  
  192.  
  193.  
  194.  
  195. Tk                                                              3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. Tk_CreateErrorHandler(3T)k Library Procedures
  203.  
  204.  
  205.  
  206.      For the Tk error handling mechanism to work properly, it  is
  207.      essential that application code never calls XSetErrorHandler
  208.      directly;      applications      should       use       only
  209.      Tk_CreateErrorHandler.
  210.  
  211.  
  212. KEYWORDS
  213.      callback, error, event, handler
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. Tk                                                              4
  262.  
  263.  
  264.  
  265.